package com.wc.AlgoOJ.LQ1451_买二赠一;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/26 22:31
 * @description http://43.138.190.70:8888/p/LQ1451
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 500010;
    static PriorityQueue<Integer> free = new PriorityQueue<>(Comparator.reverseOrder());
    static PriorityQueue<Integer> buy = new PriorityQueue<>(Comparator.reverseOrder());
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        // 刚刚开始全免费
        for (int i = 1; i <= n; i++) free.add(sc.nextInt());
        long res = 0;
        while (!free.isEmpty() || !buy.isEmpty()) {
            int first = 0, second = 0;
            // 如果说买的队列里面没有商品，就从免费的里面拿
            if (buy.size() == 0) {
                // 免费的大于等于二，可以拿两件
                if (free.size() >= 2) {
                    first = free.poll();
                    second = free.poll();
                    // 如果只有一件免费的就直接拿出来就好了
                } else if (free.size() == 1) {
                    first = free.poll();
                }
                // 如果买的里面有一件
            } else if (buy.size() == 1) {
                first = buy.poll();
                // 剩下一个从免费的里面拿
                if (!free.isEmpty()) second = free.poll();
            } else {
                // 要不就都从买的里面拿，因为够>=2的
                first = buy.poll();
                second = buy.poll();
            }
            // 如果说第二件没有商品了，说明这个是最后一件，直接买就完事了
            if (second == 0) {
                res += first;
                break;
            }
            // 否则就买这两件
            res += first + second;
            // 从免费的里面拿
            while (!free.isEmpty()) {
                // 这个是免费的
                if (free.peek() <= second / 2) {
                    free.poll();
                    break;
                }
                // 免费不了永远都免费不了了，我们是买的最大的
                buy.add(free.poll());
            }
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
